﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Z1029.NoteEditor
{
    public class EditorSettings : MonoBehaviour
    {
        public Dropdown editMode;
        public Toggle beatline;
        public Toggle trackLine;
        public InputField bpm;
        public InputField offset;
        public InputField density;
        public InputField nowDensity;
        public InputField version;
        public Toggle multiSelectNote;

        public void UpdateData()
        {
            bpm.text = LevelController.instance.bpm.ToString();
            offset.text = LevelController.instance.offset.ToString();
            density.text = LevelController.instance.tracklineDensity.ToString();
            nowDensity.text = LevelController.instance.nowDensity.ToString();
            version.text = Application.version;
            beatline.isOn = LevelController.instance.showBeatline;
            trackLine.isOn = LevelController.instance.showTrackLine;
            multiSelectNote.isOn = LevelController.instance.multiSelectNote;
            editMode.value = LevelController.instance.editMode == LevelController.EditMode.Note ? 0 : 1;
            foreach (Beatline bl in FindObjectsOfType<Beatline>())
            {
                bl.ChangeBeatlineDensity();
            }
        }

        private void Start()
        {
            UpdateData();
        }

        public void ChangeSettings()
        {
            LevelController.instance.judgelines[0].bpm = int.Parse(bpm.text);
            LevelController.instance.offset = float.Parse(offset.text);
            LevelController.instance.nowDensity = int.Parse(nowDensity.text);
            LevelController.instance.tracklineDensity = float.Parse(density.text);
            LevelController.instance.showBeatline = beatline.isOn;
            LevelController.instance.multiSelectNote = multiSelectNote.isOn;
            LevelController.instance.showTrackLine = trackLine.isOn;
            
            LevelController.instance.editMode = editMode.value==0?LevelController.EditMode.Note:LevelController.EditMode.Event;
            LevelController.instance.ChangeMode();
            UpdateData();
        }


    }
}